﻿#pragma once
#include "../../../Common/d3dUtil.h"

class BlurFilter
{
public:
    BlurFilter(
        ID3D12Device* device,
        UINT width, UINT height,
        DXGI_FORMAT format);

    BlurFilter(const BlurFilter& rhs) = delete;
    BlurFilter& operator=(const BlurFilter& rhs) = delete;
    ~BlurFilter() = default;

    void BuildDescriptors(
       CD3DX12_CPU_DESCRIPTOR_HANDLE hCpuDescriptor,
       CD3DX12_GPU_DESCRIPTOR_HANDLE hGpuDescriptor,
       UINT descriptorSize);

    void OnResize(UINT newWidth,UINT newHeight);

    void Excute(
        ID3D12GraphicsCommandList* cmdList,
        ID3D12RootSignature* rootSig,
        ID3D12PipelineState* horzBlurPSO,
        ID3D12PipelineState* vertBlurPSO,
        ID3D12Resource* input,
        int blurCount);

    ID3D12Resource* Output();

    int DescriptorCount();
private:
    void BuildResources();
   
    void BuildDescriptors();

    std::vector<float> CalcGaussWeights(float sigma);
private:
    const int MaxBlurRadius = 5;

    ID3D12Device* md3dDevice;

    UINT mWidth;
    UINT mHeight;
    DXGI_FORMAT mFormat;

    CD3DX12_CPU_DESCRIPTOR_HANDLE mBlur0CpuSrv;
    CD3DX12_CPU_DESCRIPTOR_HANDLE mBlur0CpuUav;

    CD3DX12_CPU_DESCRIPTOR_HANDLE mBlur1CpuSrv;
    CD3DX12_CPU_DESCRIPTOR_HANDLE mBlur1CpuUav;

    CD3DX12_GPU_DESCRIPTOR_HANDLE mBlur0GpuSrv;
    CD3DX12_GPU_DESCRIPTOR_HANDLE mBlur0GpuUav;

    CD3DX12_GPU_DESCRIPTOR_HANDLE mBlur1GpuSrv;
    CD3DX12_GPU_DESCRIPTOR_HANDLE mBlur1GpuUav;
    

    Microsoft::WRL::ComPtr<ID3D12Resource> mBlurMap0 = nullptr;
    Microsoft::WRL::ComPtr<ID3D12Resource> mBlurMap1 = nullptr;
};
